package com.goodving.guli.bt.utils;

import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.GattUtils;
import com.goodving.guli.bt.profile.scale.HeartRateInfo;
import com.goodving.guli.bt.profile.scale.ScaleWeightInfo;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Created by john on 2015/11/30.
 */
public class ProfileUtils { // C3950a
    private static final String f19918a = "ProfileUtils";

//    public static int m25638a(InputStream inputStream) {
//        byte[] bArr = new byte[4];
//        inputStream.skip(1056);
//        inputStream.read(bArr, 0, 4);
//        return (bArr[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((((bArr[3] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[2] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8));
//    }

    public static int m25639a(String str) {
        String substring = str.substring(1);
        GuliLog.tracePrintInfo(f19918a, "weight fw version:" + substring);
        String[] split = substring.split("\\.");
        if (split.length != 3) {
            return -1;
        }
        int parseInt = Integer.parseInt(split[0]);
        int parseInt2 = Integer.parseInt(split[1]);
        return (Integer.parseInt(split[2]) & HeartRateInfo.HR_EMPTY_VALUE) | ((parseInt & 16711680) | ((parseInt2 & HeartRateInfo.HR_EMPTY_VALUE) << 8));
    }

    public static int m25640a(byte[] bArr) {
        return ((((bArr[1059] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[1058] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[1057] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[1056] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static ScaleWeightInfo m25641a(byte[] bArr, boolean z, boolean z2) {
        GuliLog.m12370d(f19918a, "value:" + GattUtils.m25335b(bArr));
        if (bArr.length != 10 || (bArr[0] & HeartRateInfo.HR_EMPTY_VALUE) == 0) {
            GuliLog.m12370d(f19918a, "wrong weight data,ignore!!!");
            return null;
        }
        int i;
        float f = (float) (((bArr[2] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (bArr[1] & HeartRateInfo.HR_EMPTY_VALUE));
        if ((bArr[2] & HeartRateInfo.HR_EMPTY_VALUE) == HeartRateInfo.HR_EMPTY_VALUE && (bArr[1] & HeartRateInfo.HR_EMPTY_VALUE) == 240) {
            i = 0;
        } else {
            i = bArr[0] & ScaleWeightInfo.f19761m;
            f = i == 0 ? f / 200.0f : f / 100.0f;//CropOverlayView.f15889a;
        }
        Calendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.clear();
        boolean z3 = (bArr[0] & ScaleWeightInfo.stable) != 0;
        boolean z4 = (bArr[0] & ScaleWeightInfo.finish) != 0;
        gregorianCalendar.set(Calendar.YEAR, ((bArr[4] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (bArr[3] & HeartRateInfo.HR_EMPTY_VALUE));
        gregorianCalendar.set(Calendar.MONTH, bArr[5] - 1);
        gregorianCalendar.set(Calendar.DATE, bArr[6]);
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, bArr[7]);
        gregorianCalendar.set(Calendar.MINUTE, bArr[8]);
        gregorianCalendar.set(Calendar.SECOND, bArr[9]);
//        this.stable = z;
//        this.isMeasurement = z2;
//        this.isHistory = z3;
//        this.isFinish = z4;
        ScaleWeightInfo c3925e = new ScaleWeightInfo(i, f, gregorianCalendar.getTimeInMillis(), z3, z, z2, z4);
        GuliLog.m12370d(f19918a, "WeightAdvData:" + c3925e);
        return c3925e;
    }

    public static boolean m25642b(byte[] bArr) {
        long j = (((((long) (bArr[26] & HeartRateInfo.HR_EMPTY_VALUE)) << 24) | (((long) (bArr[27] & HeartRateInfo.HR_EMPTY_VALUE)) << 16)) | (((long) (bArr[28] & HeartRateInfo.HR_EMPTY_VALUE)) << 8)) | ((long) (bArr[29] & HeartRateInfo.HR_EMPTY_VALUE));
        return ((((((long) (bArr[0] & HeartRateInfo.HR_EMPTY_VALUE)) << 24) | (((long) (bArr[1] & HeartRateInfo.HR_EMPTY_VALUE)) << 16)) | (((long) (bArr[2] & HeartRateInfo.HR_EMPTY_VALUE)) << 8)) | ((long) (bArr[3] & HeartRateInfo.HR_EMPTY_VALUE))) == 2020959083 && ((((((long) (bArr[12] & HeartRateInfo.HR_EMPTY_VALUE)) << 24) | (((long) (bArr[13] & HeartRateInfo.HR_EMPTY_VALUE)) << 16)) | (((long) (bArr[14] & HeartRateInfo.HR_EMPTY_VALUE)) << 8)) | ((long) (bArr[15] & HeartRateInfo.HR_EMPTY_VALUE))) + ((((((long) (bArr[16] & HeartRateInfo.HR_EMPTY_VALUE)) << 24) | (((long) (bArr[17] & HeartRateInfo.HR_EMPTY_VALUE)) << 16)) | (((long) (bArr[18] & HeartRateInfo.HR_EMPTY_VALUE)) << 8)) | ((long) (bArr[19] & HeartRateInfo.HR_EMPTY_VALUE))) <= j && j + ((((((long) (bArr[30] & HeartRateInfo.HR_EMPTY_VALUE)) << 24) | (((long) (bArr[31] & HeartRateInfo.HR_EMPTY_VALUE)) << 16)) | (((long) (bArr[32] & HeartRateInfo.HR_EMPTY_VALUE)) << 8)) | ((long) (bArr[33] & HeartRateInfo.HR_EMPTY_VALUE))) <= ((long) bArr.length);
    }

    public static boolean m25643c(byte[] bArr) {
        return (bArr[7] & HeartRateInfo.HR_EMPTY_VALUE) == 1;
    }

    public static int m25644d(byte[] bArr) {
        return ((((bArr[8] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[9] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[10] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[11] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static int m25645e(byte[] bArr) {
        return ((((bArr[22] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[23] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[24] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[25] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static int m25646f(byte[] bArr) {
        return ((((bArr[12] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[13] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[14] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[15] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static int m25647g(byte[] bArr) {
        return ((((bArr[16] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[17] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[18] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[19] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static boolean m25648h(byte[] bArr) {
        return ProfileUtils.m25647g(bArr) + ProfileUtils.m25646f(bArr) <= bArr.length && ProfileUtils.m25647g(bArr) > 0;
    }

    public static int m25649i(byte[] bArr) {
        return ((((bArr[26] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[27] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[28] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[29] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static int m25650j(byte[] bArr) {
        return ((((bArr[30] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[31] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[32] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[33] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static boolean m25651k(byte[] bArr) {
        return ProfileUtils.m25650j(bArr) + ProfileUtils.m25649i(bArr) <= bArr.length && ProfileUtils.m25650j(bArr) > 0;
    }
}
